package com.springboot.service.impl;

import com.springboot.dto.MemorandumShowView;
import com.springboot.mapper.AssistantSelfReminderFormMapper;
import com.springboot.model.AssistantSelfReminderForm;
import com.springboot.service.MemorandumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;

@Service
public class MemorandumServiceImpl implements MemorandumService {
    @Autowired
    private AssistantSelfReminderFormMapper assistantSelfReminderFormMapper;

    @Override
    public ArrayList<MemorandumShowView> showMemorandumById(Integer assistantId){
        ArrayList<AssistantSelfReminderForm> assistantSelfReminderForms=new ArrayList<>();
        ArrayList<MemorandumShowView> memorandumShowViews=new ArrayList<>();
        try {
            assistantSelfReminderForms=assistantSelfReminderFormMapper.selectAssistantSelfReminderById(assistantId);
            int size=assistantSelfReminderForms.size();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            for(int i=0;i<size;i++)
            {

                String str = sdf.format(assistantSelfReminderForms.get(i).getCreateTime());
                MemorandumShowView memorandumShowView=new MemorandumShowView(assistantSelfReminderForms.get(i).getItemId(),assistantSelfReminderForms.get(i).getMemorandumContent(),str,assistantSelfReminderForms.get(i).getMemorandumTitle());
                memorandumShowViews.add(memorandumShowView);
            }

        }
        catch (Exception e)
        {
            e.printStackTrace();
            System.out.println("assistantSelfReminderFormMapper失败");
        }
        return memorandumShowViews;
    }

    @Override
    public int deleteMemorandumById(Integer itemId){
        int a=assistantSelfReminderFormMapper.deleteByPrimaryKey(itemId);
        return  a;
    }

    @Override
    public int updateMemorandumById(AssistantSelfReminderForm assistantSelfReminderForm){
        int a=assistantSelfReminderFormMapper.updateByPrimaryKeySelective(assistantSelfReminderForm);
        return  a;
    }

    @Override
    public int insertMemorandumById(AssistantSelfReminderForm assistantSelfReminderForm){
        int a=assistantSelfReminderFormMapper.insertSelective(assistantSelfReminderForm);
        return a;
    }

    @Override
    public int getMaxItemId(Integer assistantId){
        int a=0;
        try {
            a=assistantSelfReminderFormMapper.selectMaxId(assistantId);
        }
        catch (Exception e){
            e.printStackTrace();
            System.out.println("表空，无值");
        }
        return a;
    }
}
